package com.transpeed.payservice.pay.unionpay;

import java.io.IOException;
import java.util.HashMap;

import com.google.gson.Gson;
import com.transpeed.payservice.Utils.UmsPayUtils;
import com.transpeed.payservice.model.UmsPayQRcode;
import com.transpeed.payservice.model.UmsPayQuery;

public class UmsPayController{
	private static String SystemNumber = "3075";//系统编号
	
	public static String  getUnionQRCode(String totalmount,String carplate,String carinplace) throws IOException {
	
		String qrCodeId = UmsPayUtils.getQRCodeId(SystemNumber);//二维码ID
		String qrCodeUrl = UmsPayUtils.getQRCodeUrl(qrCodeId);
		String BillNo = UmsPayUtils.getBillNo(SystemNumber);
		
		String subject = carplate + " (" + carinplace + ")";
		
		HashMap<String, Object> UmsPayQRCode = new HashMap<String, Object>();
		UmsPayQRCode = UmsPayUtils.constructHashMap_getQRCode(subject,totalmount,BillNo, qrCodeId, SystemNumber);
		String response = UmsPayPOST.post(UmsPayQRCode);
		String BillQRCode = null;	
		Gson gson = new Gson();
		UmsPayQRcode info = gson.fromJson(response , UmsPayQRcode.class);
		
		if(info.getErrCode().equals("SUCCESS"))
			BillQRCode = info.getBillQRCode();
		else
			BillQRCode= "获取失败！";
		
		return BillQRCode+"&"+BillNo;
	}
	
	public static String  queryUnionTrade(String billNo , String billDate) throws IOException {
		
		HashMap<String, Object> UmsPayQuery = new HashMap<String, Object>();
		
		UmsPayQuery = UmsPayUtils.constructHashMap_Query(billNo, billDate);
		
		String response = UmsPayPOST.post(UmsPayQuery);
	
		Gson gson = new Gson();
		UmsPayQuery info = gson.fromJson(response , UmsPayQuery.class);
		String BillStatus = null;	
		
		if(info.getErrCode().equals("SUCCESS"))
			BillStatus = info.getBillStatus();
		else
			BillStatus= "获取失败！";
		
		System.out.println(BillStatus);
		System.out.println(info.getErrCode());
		
		
			
		return BillStatus;
	}
	
}
